<template>
  <header class="header">
    <main>
      <div class="logo-box">
        <a href="/" class="logo">
          <img src="/logo.svg" />
        </a>
      </div>
      <nav>
        <template v-for="(menu, index) in menuList" :key="index">
          <a :href="'#' + menu.id" class="item" @click.stop.prevent="handleNavClick('#' + menu.id)">
            {{ menu.text }}
          </a>
        </template>
      </nav>
    </main>
  </header>
</template>
<script>
import { scrollToDom } from '../util';

export default {
  name: 'co-header',
  data() {
    return {
      menuList: [
        {
          id: 'sec-1',
          text: 'Home',
        },
        {
          id: 'sec-2',
          text: 'About',
        },
        {
          id: 'sec-3',
          text: 'Product',
        },
        {
          id: 'sec-4',
          text: 'Contact',
        },
      ],
    };
  },
  methods: {
    handleNavClick(target) {
      scrollToDom(target);
    },
  },
};
</script>
<style lang="less" scoped>
.header {
  background-color: #fff;
  main {
    max-width: 1200px;
    padding: 15px 20px;
    margin: 0 auto;
  }

  .logo-box {
    display: flex;
    margin: 0 auto;
    justify-content: center;
    align-items: center;

    .logo {
      img {
        display: block;
        height: 34px;
        width: auto;
      }
    }
  }

  nav {
    display: flex;
    justify-content: space-around;
    margin-top: 16px;
    .item {
      height: 20px;
      line-height: 20px;
      margin: 0 18px;
      position: relative;
      font-size: 16px;
      font-weight: bold;
      cursor: pointer;
      transition: color 0.2s linear;
      color: #424c4c;

      &::after {
        content: '';
        position: absolute;
        bottom: -4px;
        left: 0;
        width: 100%;
        height: 2px;
        background-color: transparent;
        transition: background-color 0.2s linear;
      }

      &:hover {
        color: #8a7856;

        &::after {
          background-color: #8a7856;
        }
      }
    }
  }
}
</style>
